package com.faithbj.schedule;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.faithbj.common.model.CheckTotal;
import com.faithbj.service.CheckTotalService;
import com.faithbj.service.CompareService;
import com.faithbj.support.vo.CompareRequest;
import com.faithbj.webservice.WebServiceClient;

/**
 * 电子比对交换自动运行任务类
 * 
 * @author chen liu
 */
//@Component
public class CompareAutoRunJob extends AbstractJob {
    @Resource
    private CompareService compareService;

    @Resource
    private CheckTotalService ctService;

    @Override
    protected void executeInternal() throws Exception {
        System.out.println("*********开始执行定时任务");
        // 查询需要生成批次的受理记录
        Map<String, List<CheckTotal>> batchingMap = ctService.getCheckTotalMapForBatching();

        // 生成批次,发送委办
        Object resultObj = compareService.genearateBatch(batchingMap);
        if (resultObj != null && !(resultObj instanceof String)) {
            Map<String, Map<String, List<CompareRequest>>> resultMap = (Map<String, Map<String, List<CompareRequest>>>) resultObj;
            System.out.println("fullCompareReqMap size is : " + resultMap.keySet().size());
            for (String regionId : resultMap.keySet()) {
                for (String depNum : resultMap.get(regionId).keySet()) {
                    WebServiceClient.returnOfficalData(depNum, resultMap.get(regionId).get(depNum));
                }
            }
        } else {
            System.out.println((String) resultObj);
        }
        System.out.println("*********结束执行定时任务");
    }
}